package com.gym.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gym.client.UserClient;
import com.gym.pojo.User;
import com.gym.utils.MD5Util;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
public class UserController {
    @Resource
    private UserClient userClient;

    @RequestMapping("/listUser")//查询全部用户
    public Object userList(String name){
        List<User> list=userClient.selListUser(name);
        Object obj=JSON.toJSON(list);
        return obj;
    }

    @RequestMapping("/selListUser")
    public JSONObject selListUser(String name, int page, int limit){
        return userClient.selListUser(name,page,limit);
    }

    @RequestMapping("/saveUser")//新增用户
    public boolean saveUser( User user){
        return  userClient.insUser(user);
    }

    @RequestMapping("/updUser")//修改用户信息
    public boolean updUser( User user){
        return  userClient.updUser(user);
    }

    @RequestMapping("/delUserById")//删除用户信息
    public boolean delUserById(int userId){
        return userClient.delUserById(userId);
    }

    @RequestMapping("/selByAccount")//验证账号是否重复
    public int selByAccount(String account) {
        return userClient.selByAccount(account);
    }

    @RequestMapping("/provingByPwd")//验证旧密码是否正确
    public boolean provingByPwd(int userId,String pwd,String name){
        return userClient.provingByPwd(userId,pwd,name);
    }
    @RequestMapping("/selectsj")
    public JSONObject selectsj(String username,int userId,int page,int limit){
        return userClient.selectsj(username,userId,page,limit);
    }
    @RequestMapping("/updUserBypwd")//修改密码
    public boolean updUserBypwd(int userId, String pwd,String name) {
        return userClient.updUserBypwd(userId,MD5Util.MD5(pwd,name));
    }

    @RequestMapping("/selIdByAcc")
    public int selIdByAcc(int account){
        int sun=userClient.selIdByAcc(account);
        System.out.println("会员编号"+sun);
        return sun;
    }
}
